package gestao_proj;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.UIManager;

/**
 * Basicamente a Janela Principal
 * 
 * @author Omar Castro
 * 
 */
@SuppressWarnings("serial")
public class Janela extends JFrame {
	public static Painel grafo;

	public Janela() {
		super("Projecto");
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			System.out.println("Error setting native LAF: " + e);
		}
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setContentPane(new Start(this));
		this.setJMenuBar(new Menu());
		this.pack();
		this.setVisible(true);
	}

	public static void main(String[] args) {
		new Janela();
	}
}

/**
 * Menu Usado para a Janela Usa-se para cirar Novo Projecto, Carregar Projecto,
 * Gravar e sair
 * 
 * @author Omar Castro
 * 
 */
@SuppressWarnings("serial")
class Menu extends JMenuBar {
	private JMenu file;
	private JMenuItem menuItem;

	public Menu() {
		file = new JMenu("File");

		menuItem = new JMenuItem("New Project");
		menuItem.getAccessibleContext().setAccessibleDescription(
				"The only menu in this program that has menu items");
		menuItem.setMnemonic(KeyEvent.VK_1);
		menuItem.addActionListener(Start.newProject.getActionListeners()[0]);
		file.add(menuItem);

		menuItem = new JMenuItem("Open...");
		menuItem.getAccessibleContext().setAccessibleDescription(
				"The only menu in this program that has menu items");
		menuItem.setMnemonic(KeyEvent.VK_1);
		menuItem.addActionListener(Start.loadProject.getActionListeners()[0]);
		file.add(menuItem);

		menuItem = new JMenuItem("Save as...");
		menuItem.setMnemonic(KeyEvent.VK_2);
		menuItem.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				JFileChooser fc = new JFileChooser();
				fc.addChoosableFileFilter(Start.filtro);
				int returnVal = fc.showSaveDialog(Menu.this);
				if (returnVal == JFileChooser.APPROVE_OPTION) {
					Data.saveProj(fc.getSelectedFile());
				}
			}

		});
		file.add(menuItem);

		menuItem = new JMenuItem("Close");
		menuItem.setMnemonic(KeyEvent.VK_3);
		menuItem.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}

		});
		file.add(menuItem);
		this.add(file);

	}
}
